using AndyPike.Unfuddle.Contracts;
using AndyPike.Unfuddle.Entities.Projects;

namespace AndyPike.Unfuddle.Commands.Projects
{
    /// <summary>
    /// Provides a command for creating a new project on the Unfuddle server
    /// </summary>
    public class CreateProject : IUnfuddleChangeCommand
    {
        private readonly Project project;

        /// <summary>
        /// Instantiates the CreateProject command
        /// </summary>
        /// <param name="project">The new project to create</param>
        public CreateProject(Project project)
        {
            this.project = project;
        }

        /// <summary>
        /// Creates a new project on the Unfuddle server
        /// </summary>
        /// <param name="service">The Unfuddle service to use when executing the command</param>
        public void Execute(IUnfuddleService service)
        {
            GuardAgainst.ArgumentNull(service, "service");

            project.Validate(EntityValidationContext.Creating);

            string url = service.BuildUrl("projects");
            service.InvokeRequest(url, HttpMethod.POST, project);
        }
    }
}